package lunbo

import (
	"context"
	"fmt"

	"server/amtf"
	"server/global"
	"server/model/system"
	"github.com/gin-gonic/gin"
	"github.com/pkg/errors"
	"go.uber.org/zap"
)

func A成组件() (组件 *amtf.S组件) {
	组件 = &amtf.S组件{
		Name:   "轮播图",
		A英文名:   "lunbo",
		Amodel: S轮播图model{},
	}
	return
}

// 👇作废保留
type S轮播图 struct {
	Name   string
	A英文名   string
	Amodel S轮播图model
	Aapi   *S轮播图api
}

var A轮播图 = &S轮播图{
	Name: "轮播图",
	A英文名: "lunbo",
}

// type S轮播图2 struct {
// 	Name   string
// 	A英文名   string
// 	Amodel S轮播图model
// 	A搜索req S轮播图搜索req
// }

// var A轮播图2 = &amtf.S组件{
// 	Name: "轮播图",
// 	A英文名: "lunbo",
// 	Aapi: nil,
// 	// Aservice: A轮播图service,
// 	Amodel: S轮播图model{},
// }

// var api = &amtf.S基础api{
// 	A组件: A轮播图2,
// }

func A注册组件(PrivateGroup *gin.RouterGroup, PublicRouter *gin.RouterGroup, engine *gin.Engine) {
	// amtf.A注册组件(PrivateGroup, PublicRouter, engine, A老鱼商店, A轮播图)

	ctx := context.Background()
	err := global.GVA_DB.WithContext(ctx).AutoMigrate(S轮播图model{})
	if err != nil {
		err = errors.Wrap(err, "注册表失败!")
		zap.L().Error(fmt.Sprintf("%+v", err))
	}

	PrivateGroup1 := PrivateGroup.Group("lunbo")
	// PublicRouter1 := PublicRouter.Group("lunbo")

	group := PrivateGroup1
	group.POST("", A轮播图api.A增)
	group.DELETE("", A轮播图api.A删)
	group.PUT("", A轮播图api.A改)
	group.GET("", A轮播图api.A查)

	entities := []system.SysApi{
		{ApiGroup: "老鱼商店/轮播图", Method: "POST", Path: "/lysd/lunbo", Description: "增轮播图"},
		{ApiGroup: "老鱼商店/轮播图", Method: "GET", Path: "/lysd/lunbo", Description: "查轮播图"},
		{ApiGroup: "老鱼商店/轮播图", Method: "PUT", Path: "/lysd/lunbo", Description: "改轮播图"},
		{ApiGroup: "老鱼商店/轮播图", Method: "DELETE", Path: "/lysd/lunbo", Description: "删轮播图"},
	}
	amtf.A注册api(entities...)

	目录 := []system.SysBaseMenu{
		{MenuLevel: 0, Hidden: false, Path: "lysd", Name: "老鱼商店", Component: "view/routerHolder.vue", Sort: 0, Meta: system.Meta{Title: "老鱼商店", Icon: "shop"}},
		{MenuLevel: 0, Hidden: false, Path: "lunbo", Name: "老鱼商店/轮播图/list", Component: "找aa", Sort: 1, Meta: system.Meta{Title: "轮播图", Icon: "picture-filled"}},
	}
	amtf.A注册目录(目录...)
}
